package org.goose.web.controllers;
import java.rmi.RemoteException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import org.goose.web.RequestMethod;
import org.goose.web.annotations.Controller;
import org.goose.web.annotations.RequestMapping;

import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.Day;
import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.Drink;
import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.Food;
import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.GetMenuProcessProxy;
import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.holders.DayArrayHolder;
import com.oracle.xmlns.IngredientService.MenuServer2.GetMenuProcess.holders.DrinkArrayHolder;
import com.oracle.xmlns.PatientService.getOrdersProcess.getOrderProcess.Order;
import com.oracle.xmlns.PatientService.getOrdersProcess.getOrderProcess.Orders;

@Controller
public class OrderController {
	private final static Logger logger = Logger
			.getLogger(OrderController.class);
	
	@RequestMapping(value = "/index", method=RequestMethod.GET)
	public String getIndex(HttpServletRequest request, VelocityContext context, Map pathVariables){
		logger.info("Returning index.vm");
		
		//===== TEST DATA
		
				Orders order1 =
						new Orders(0, 0, 3, 1, 1);
				Orders order2 =
						new Orders(1, 0, 3, 1, 1);
				Orders order3 =
						new Orders(2, 0, 3, 1, 1);
				Orders[] orders = {order1, order2, order3};
				
				Drink[] drinks = {
						new Drink(0, "Cola"),
						new Drink(1, "Koffie"),
						new Drink(2, "Thee")
				};
				
				Food food1 = new Food(0,"Meatball Madness", "Spaghetti, Tomaat, Gehakt");
				Food food2 = new Food(1, "Happy Raviolli", "Raviolli, Spinache, Ham");
				Food food3 = new Food(2, "Hollandse Pot", "Aardappel, Andijvie, Rookworst");
				Food food4 = new Food(3, "Tosti", "Brood, Ham, Kaas");
				Food food5 = new Food(4, "Bulky Beef", "Biefstuk, boontjes en pepersaus");
				Food food6 = new Food(5, "Broodje Kaas", "Brood, kaas en boter");
				Food food7 = new Food(5, "Broodje Ham", "Brood, ham en boter");
				Food[] foods = {food1, food2, food3, food4, food5, food6, food7};
				
				
				Day[] days = {
						new Day(0, "maandag", 0, drinks[0], food1, foods),
						new Day(1, "maandag", 1, drinks[2], food2, foods),
						new Day(2, "maandag", 2, drinks[0], food3, foods),
						new Day(3, "dinsdag", 0, drinks[1], food4, foods),
						new Day(4, "dinsdag", 1, drinks[1], food5, foods),
						new Day(5, "dinsdag", 2, drinks[2], food6, foods),
						new Day(6, "woensdag", 0, drinks[0], food7, foods),
						new Day(7, "woensdag", 1, drinks[0], food1, foods),
						new Day(8, "woensdag", 2, drinks[1], food2, foods),
						new Day(9, "donderdag", 0, drinks[0], food3, foods),
						new Day(10, "donderdag", 1, drinks[0], food4, foods),
						new Day(11, "donderdag", 2, drinks[2], food5, foods),
						new Day(12, "vrijdag", 0, drinks[0], food6, foods),
						new Day(13, "vrijdag", 1, drinks[2], food7, foods),
						new Day(14, "vrijdag", 2, drinks[1], food1, foods),
						new Day(15, "zaterdag", 0, drinks[0], food2, foods),
						new Day(16, "zaterdag", 1, drinks[1], food3, foods),
						new Day(17, "zaterdag", 2, drinks[1], food4, foods),
						new Day(18, "zondag", 0, drinks[0], food5, foods),
						new Day(19, "zondag", 1, drinks[2], food6, foods),
						new Day(20, "zondag", 2, drinks[0], food7, foods)
				};
				
				//========================
				
				context.put("drinks", drinks);
				context.put("days", days);
		
		return "index.vm";
	}
	
	@RequestMapping(value = "/maaltijden", method=RequestMethod.GET)
	public String getMeals(HttpServletRequest request, VelocityContext context, Map pathVariables){
		logger.info("Returning maaltijden.vm");
		
		Order order1 = new Order(5, "Broodje Ham", "Brood, ham en boter", "Zuivel", "Ochtend", 766);
		Order order2 = new Order(3, "Tosti", "Brood, Ham, Kaas", "Zuivel", "Ochtend", 386);
		Order order3 = new Order(5, "Broodje Kaas", "Brood, kaas en boter", "Zuivel", "Ochtend", 148);
		Order order4 = new Order(2, "Hollandse Pot", "Aardappel, Andijvie, Rookworst", "Zetmeel", "Diner", 454);
		Order order5 = new Order(1,"Meatball Madness", "Spaghetti, Tomaat, Gehakt", "Tomaten", "Diner", 343);
		Order order6 = new Order(1, "Happy Raviolli", "Raviolli, Spinache, Ham", "Gluten", "Diner", 296);
		Order order7 = new Order(4, "Bulky Beef", "Biefstuk, boontjes en pepersaus", "/", "Diner", 207);
		
        
		
		Order[] orders  = {order1, order2, order3, order4, order5, order6, order7};
		
		context.put("arrFood", orders);
		return "maaltijden.vm";
	}
	
	@RequestMapping(value = "/index", method=RequestMethod.POST)
	public String addOrder(HttpServletRequest request, VelocityContext context, Map pathVariables)
	{
		return "raw:true";
	}
	
}
